var CONFIG = {};
//CONFIG['baseUrl'] = 'http://172.16.95.99:8026/BankBusiness.asmx';
CONFIG['baseUrl'] = 'http://172.16.95.99:8026/BankBusiness.asmx';
var deviceWidth=document.documentElement.clientWidth;
document.documentElement.style.fontSize = deviceWidth / 128.1+ 'px';//以1281屏幕为标准

function logout() {
	plus.storage.clear();
	var launchId = plus.webview.getLaunchWebview().id;
	mui.openWindow({
		id: launchId
	});
	var wall = plus.webview.all();
	mui.each(wall, function(i, item){
		if(item.id!=launchId){
			item.close();
		}
	});
}
//判断是否在数组里
function contains(arr, obj) {  
    var i = arr.length;  
    while (i--) {  
        if (arr[i] === obj) {  
            return true;  
        }  
    }  
    return false;  
}

function setFocus(id){
	document.getElementById(id).focus()
}

function getResult(result, name){
	plus.nativeUI.closeWaiting();
	try{
		if(result!=''){
			return JSON.parse(result.split('<'+name+'>')[1].split('</'+name+'>')[0].replace(/[\r\n]/g,''));
		}
		return '';
	}catch(err){
		mui.alert('返回数据解释异常，请重试', '提示', '确定');
	}
}


//define
var xmlhttp;
var value = new Array();
var variable = new Array();

//Get Request Data's length
function getlen(str) {
	var bytesCount = 0;
	for(var i = 0; i < str.length; i++) {
		var c = str.charAt(i);
		if(/^[\u0000-\u00ff]$/.test(c)) //匹配双字节
		{
			bytesCount += 1;
		} else {
			bytesCount += 2;
		}
	}
	return bytesCount;

}

//Create XMLHttpRequest Object
function createXMLHttpRequest() {
	xmlhttp = new plus.net.XMLHttpRequest();

}

//send Request By HTTP POST

function RequestByPost(method, variable, value, url, _Namespace, adorn, handleStateChange) {
	plus.nativeUI.showWaiting( "等待中..." );
	createXMLHttpRequest();
	var data;
	data = '<?xml version="1.0" encoding="utf-8"?>';
				data = data + '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
				data = data + '<soap12:Body>';
				data = data + '<' + method + ' xmlns="' + _Namespace + '"><xml><![CDATA[';
	if(adorn){
		for(var i = 0; i < adorn.length; i++) {
			data = data + '<' + adorn[i] + '>';
		}
	}
	for(var i = 0; i < variable.length; i++) {
		data = data + '<' + variable[i] + '>' + value[i] + '</' + variable[i] + '>';
	}
	if(adorn){
		for(var i = adorn.length-1; i >= 0; i--) {
			data = data + '</' + adorn[i] + '>';
		}
	}
	data = data + ']]></xml></' + method + '>';
	data = data + '</soap12:Body>';
	data = data + '</soap12:Envelope>';

	xmlhttp.onload = handleStateChange;
	//日志
	xmlhttp.onerror = function(e){
		mui.toast('请求错误',{ duration:'long', type:'div' })
		plus.storage.setItem(new Date().toLocaleString(), '【请求错误】'+xmlhttp.status+':'+xmlhttp.statusText);
		plus.nativeUI.closeWaiting();
	}
	xmlhttp.ontimeout = function(e){
		mui.toast('请求超时',{ duration:'long', type:'div' })
		plus.storage.setItem(new Date().toLocaleString(), '【请求超时】'+xmlhttp.status+':'+xmlhttp.statusText);
		plus.nativeUI.closeWaiting();
	}
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8");
	//xmlhttp.setRequestHeader ("Content-Length",''+getlen(data)); 
	//xmlhttp.setRequestHeader ("Access-Control-Allow-Origin", "*"); 
	xmlhttp.setRequestHeader("SOAPAction", _Namespace + method);
	xmlhttp.send(data);
}
//检查自动更新   
function svn(versionNo,url) {   
    var xhr_svn = new plus.net.XMLHttpRequest();  
    xhr_svn.onreadystatechange = function() { 
        if (xhr_svn.readyState == 4) {  
            if (xhr_svn.status == 200) {   
                var res = JSON.parse(xhr_svn.responseText); 
                if (res.state == 'yes') {   
                    if (res.mark != versionNo) {
						plus.nativeUI.showWaiting('有新版需要更新，正在更新中，请勿关闭');  
                            var dtask = plus.downloader.createDownload(res.url, {}, function(d, status) {   
                                if (status == 200) { // 下载成功     
                                    plus.runtime.install(d.filename);   
                                } else { //下载失败   
                                    alert("Download failed: " + status);   
                                }   
                            });   
                            dtask.start();                              
                    } else {   
                        console.log('已经是最新版本');   
                    }   
                }   
            } else {   
                plus.nativeUI.toast( "网络连接错误！");   
            }   
        }   
    }   
    xhr_svn.open("GET", url);//这里的地址是上面json文件的地址   
    xhr_svn.send();     
} 